<template>
	<view class="order-detail-app">
		<!--
		<view class="field-image">
			<image class="field-image-item" src="http://admin.zhongax.com/image/getByImageId?imageId=3a745ea9-245b-443c-b30c-19fb1f5058b6" />
			<view class="field-image-name">合道</view>
		</view>
		<view class="field">
			<view class="title">地址:</view>
			<view class="value">厦门市翔安区永利大厦17层</view>
		</view>
		<view class="field">
			<view class="title">茶室名:</view>
			<view class="value">厦门翔安洋塘永利店</view>
		</view>
		<view class="field">
			<view class="title">房间编号:</view>
			<view class="value">{{item.roomName}}</view>
		</view>
		<view class="field">
			<view class="title">订单编号:</view>
			<view class="value">{{item.orderNO}}</view>
		</view>
		<view class="field">
			<view class="title">开始时间:</view>
			<view class="value">{{item.startTime}}</view>
		</view>
		<view class="field">
			<view class="title">结束时间:</view>
			<view class="value">{{item.endTime}}</view>
		</view>
		<view class="field" v-if="item.money">
			<view class="title">消费金额:</view>
			<view class="value">{{item.money}}元</view>
		</view>
		<view class="buttons">
			<button class="btn btn-primary">开大门</button>
			<button class="btn btn-primary">开包厢</button>
		</view>
		-->
		<view class="alert">
			<view>温馨提示：</view>
			<view>预约前30分钟至订单结束才可开启大门</view>
		</view>
		<view class="field-image">
			<image class="field-image-item" :src="house.images" />
			<view class="field-image-name">{{room.roomName}}</view>
		</view>
		<view class="field">
			<view class="title">茶室名:</view>
			<view class="value">{{house.name}}</view>
		</view>
		<view class="field">
			<view class="title">地址:</view>
			<view class="value">{{house.address}}</view>
		</view>
		<view class="field">
			<view class="title">房间编号:</view>
			<view class="value">{{room.roomNO}}</view>
		</view>
		<view class="field">
			<view class="title">订单编号:</view>
			<view class="value">{{item.orderNO}}</view>
		</view>
		<view class="field">
			<view class="title">开始时间:</view>
			<view class="value">{{item.startTime}}</view>
		</view>
		<view class="field">
			<view class="title">结束时间:</view>
			<view class="value">{{item.endTime}}</view>
		</view>
		<!-- v-if="canOpen" -->
		<view class="buttons" >
			<view class="btn" @click="openHouseDoor">开大门</view>
			<view class="btn" @click="openRoomDoor">开包厢</view>
		</view>
	</view>
</template>

<script>
	import util from '@/libs/util.js'
  import globalConfig from "@/config";
  const baseHttp = globalConfig.API_HOST

	export default {
		data() {
			return {
				isLogin: false,
				canOpen: true,
        baseHttp: baseHttp,
				payRenewDialog:{
					show: false,
					orderNO: ''
				},
				tab: {
					current: null,
					items: [
						{value:null,label:'茶室消费'}
					]
				},
				room: {
					roomId: "",	//包厢id
					teamhouseId: "",	//茶室id
					roomType: "",	//包厢类型（预留）
					roomLevel: "",	//包厢等级（预留）
					roomState: "",	//包厢状态
					roomNO: "",	//包厢编号
					roomName: "",	//包厢名称
					images: "",	//包厢图片
					updateTime: "",	//更新时间
					remark: "",	//备注
					orderUserId: "",	//预约用户ID
					orderTime: ""	//预约时间
				},
				house: {
					address: "",
					des: "",
					images: "",
					joinTime: "",
					lat: "",
					lon: "",
					name: "",
					remark: "",
					teaHouseId: "",
					tel: ""
				},
				orderNO: '',
				item: {
					orderNO : "",
					teahouseId : "",
					teahouseName : "",
					roomId : "",
					roomName : "",
					userId : "",
					userPhone : "",
					orderType : "",
					startTime : "",
					endTime : "",
					money : "",
					payState : "",
					remark : "",
					rentMins : "",
					predictMoney : ""
				}
			};
		},
		onLoad(params) {	
			this.orderNO = params.orderNO;
			
		},
		onShow() {
			if (global.isLogin()) {
				this.getDetail()
				this.isLogin = true
			} else {
				this.isLogin = false
				this.goPage('/pages/user/auth/auth');
				return false;
			}
		},
		onReachBottom() {

		},
		components: {

		},
		methods: {
			...util,
			openHouseDoor() {
				this.$api.post('/roomOrder/shareControlMachine', {
					orderNO: this.orderNO,
					machineType: 3,
					state: 1
				}).then((response) => {
					if (response.ret===1) {
						this.$Message.success("操作成功")
					} else {
						this.$Message.error(response.msg)
					}
				});
			},
			openRoomDoor() {
				this.$api.post('/roomOrder/shareControlMachine', {
					orderNO: this.orderNO,
					machineType: 0,
					state: 1
				}).then((response) => {
					if (response.ret===1) {
						this.$Message.success("操作成功")
					} else {
						this.$Message.error(response.msg)
					}
				});
			},
			dateToTime(date) {
				if (uni.getSystemInfoSync().platform == 'ios') {
					date = date.replace('/-/g','/');
				}
				let d = new Date(date);
				let t = d.getTime();
				return t;
			},
			getCurrentTime() {
				let t = new Date().getTime();
				return t;
			},
			getDetail() {
				this.$api.post('/roomOrder/shareGetOrder',
				  {
					orderNO: this.orderNO
				  }
				).then((response) => {

				  if (response.ret===1) {
					  /*
					  this.$nextTick(() => {
					  	order.roomName = response.data.roomName;
					  	this.listData.items[i].roomName = response.data.roomName;
					  	console.log("roomName:"+this.listData.items[i].roomName);
					  })
					  */
					  this.item = response.data;
					  
					  //判断开始时间，结束时间，canOpen
					  let startTime = this.dateToTime(this.item.startTime);
					  let endTime = this.dateToTime(this.item.endTime);
					  let currentTime = this.getCurrentTime();
					  
					  /*
					  if (currentTime > (startTime-1800000) && currentTime < endTime) {
						  this.canOpen = true;
					  } else {
						  this.canOpen = false;
					  }
					  */
					  
					  if (this.item.canOpen===1) {
						  this.canOpen = true;
					  } else {
						  this.canOpen = false;
					  }
					  
					  this.$api.post('/teaHouse/getById',
					    {
							teaHouseId: this.item.teaHouseId
					    }
					  ).then((response) => {
					    if (response.ret===1) {
							this.house = response.data
					    } else {
					  	
					    }
					  });
					  
					  this.$api.post('/room/getById',
					    {
					  		roomId: this.item.roomId
					    }
					  ).then((response) => {
					    if (response.ret===1) {
							this.room = response.data
					    } else {
					  	
					    }
					  });
					  
					  //获取茶室信息，获取房间信息
					  
				  } else {
					this.$Message.error(response.msg)
					this.canOpen = false;
				  }
				});
			},
			goPage(url) {
				uni.navigateTo({
					url: url
				})
			}
		}
	}
</script>

<style lang="scss">
	page{
		background-color: $uni-bg-color-grey;
	}
	.order-detail-app{
		font-size:28upx;
		padding:50upx;
		background-color: white;
		.alert {
		    position: relative;
		    padding: 24rpx 48rpx 24rpx 48rpx;
		    border-radius: 12rpx;
		    color: #515a6e;
		    font-size: 28rpx;
		    line-height: 48rpx;
		    margin-bottom: 30rpx;
		    border: 1px solid $uni-theme-color;
		    background-color: rgba(63, 135, 109, 0.1);
		}
		
		.field-image{
			display: flex;
			align-items: center;
			margin-bottom:20upx;
			.field-image-item{
				width:200upx;
				height:200upx;
				background-color: #ccc;
				border-radius: 10upx;
			}
			.field-image-name{
				margin-left:50upx;
			}
		}
		.field{
			padding:10upx 0;
			display: flex;
			flex-direction: row;
			.title{width:200upx;color:#999;}
			.value{flex:1;text-align: right;}
		}
		
		.buttons{
			display: flex;
			justify-content: space-between;
			margin-top:50upx;
			.btn{
				width: 250upx;
				border-radius: 30upx;
				background-color: $uni-theme-color;
				color: white;
				padding: 20upx;
				text-align: center;
			}
		}
	}

</style>